/*
 * @Author: liuxinyea
 * @Date: 2024-08-11 10:17:40
 * @LastEditors: liuxinyea
 * @LastEditTime: 2024-08-11 10:48:25
 * @Description: 这是单例模式的基类，使用泛型
 */

import { Component } from "cc"

export class SingleInstanceWithCom extends Component{
    private static _instance: any = null
    
    static getInstance<T>(): T {
        if (this._instance == null) {
            this._instance = this
        }
        return this._instance
    }
    // 因为要与编辑器中的属性值进行绑定，所以需要重写onLoad方法获取单例
    protected onLoad(): void {
        if (SingleInstanceWithCom._instance == null) {
            SingleInstanceWithCom._instance = this
        }else{
            this.node.destroy()
        }
    }
}